package com.bnzj.cloud.business.core.service;

import com.bnzj.cloud.business.core.persistence.entity.SysResourceMeta;
import com.bnzj.cloud.business.core.persistence.repository.SysResourceMetaRepository;
import com.bnzj.cloud.business.core.persistence.repository.SysUserRepository;
import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Barry
 * @createDate 2020/3/27
 * @description
 */
@Service
public class SysResourceMetaService extends BaseService<SysResourceMetaRepository, SysResourceMeta, Long> {
    public static QueryHelpBean getQueryHelpBean() {
        String selectSQL = "SELECT * ";
        String whereSQL = " FROM bnz_sys_resource_meta  where 1=1  ";
        QueryHelpBean queryBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL, SysResourceMeta.class);
        return queryBean;
    }

    public List<SysResourceMeta> findByResourceId(Long resouceId) {
        return this.repository.findByResourceId(resouceId);
    }

    @Autowired
    SysUserRepository sysUserRepository;

    public List<SysResourceMeta> findCurrentUserMetaByParentId(String userName, Long resourceId) {
//        SysUser byAccount = sysUserRepository.findByAccount(userName);
//        List<SysRoleUser> roleUserList = byAccount.getRoleUserList();
//        Set<AuthRole> roleSet = userInfo.getRoleSet();
//        HashSet<AuthResourceMenu> authResourceMenus = new HashSet<>();
//        roleSet.stream().forEach(authRole->{
//            authResourceMenus.addAll(authRole.getResourceSet());
//        });
//        List<AuthResourceMenu> collect = authResourceMenus.stream().filter(resource -> pId.equals(resource.getParentId())).collect(Collectors.toList());
        return null;
    }
}
